package com.spark.usermusicService.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.spark.usermusicService.entity.LoveMusic;
import com.spark.usermusicService.entity.Music;
import com.spark.usermusicService.mapper.JoinMusicMapper;
import com.spark.usermusicService.mapper.LoveMusicMapper;
import com.spark.usermusicService.service.LoveMusicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 我的喜欢 服务实现类
 * </p>
 *
 * @author wzk
 * @since 2021-07-01
 */
@Service
public class LoveMusicServiceImpl extends ServiceImpl<LoveMusicMapper, LoveMusic> implements LoveMusicService {
    @Resource
    private JoinMusicMapper mapper;

    @Override
    public List<LoveMusic> getLoveMusicByUserId(String userId) {
        QueryWrapper<LoveMusic> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<LoveMusic> list = list(queryWrapper);
        return list;
    }

    @Override
    public boolean deleteLoveMusicByUserId(String userId) {
        UpdateWrapper<LoveMusic> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id", userId);
        boolean b = remove(updateWrapper);
        return b;
    }

    @Override
    public List<Music> getLoveMusicDetailsByUserId(String userId) {
        List<Music> musicList = mapper.lovelistJoinMusic(userId);
        return musicList;
    }
}
